home *** CD-ROM | disk | FTP | other *** search
- Path: fido.asd.sgi.com!news
- From: Emmanuel Mogenet <mgix@aw.sgi.com>
- Newsgroups: comp.lang.c++
- Subject: C++ Shortcomings ?
- Date: Thu, 14 Mar 1996 13:24:29 -0800
- Organization: Alias/Wavefront
- Message-ID: <31488E8D.167E@aw.sgi.com>
- NNTP-Posting-Host: mgixppp.sb.aw.sgi.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; IRIX 5.3 IP22)
-
- Here are two questions about C++
-
- 1. Class dependent private interfaces.
- ---------------------------------------
- One thing I'd love to be able to do in C++ is the following thing:
-
- class ManagerForClassA
- {
- public:
- ManagerForClassA();
- ~ManagerForClassA();
- private:
- ...
- };
-
- class ClassASpecialClient
- {
- public:
- ClassASpecialClient();
- ~ClassASpecialClient();
- private:
- ...
- }
-
- class A
- {
- public:
- A();
- ~A();
-
- restricted ManagerForClassA:
- void SomeMethodOnlyCallableOnlyByManagerForClassA();
-
- restricted ClassASpecialClient:
- void SomeMethodOnlyCallableOnlyByClassASpecialClient();
-
- restricted ClassASpecialClient ManagerForClassA:
- void SomeMethodOnlyCallableByBoth();
- }
-
- In other word, make portions of the interface to a class private to
- only some classes.
-
- 1. Wouldn't that be nicer than the friend mechanism that cracks
- open a class a spill its guts ?
- 2. Is there a clean way to achieve in today's C++ standard ?
- 3. Or is it a bad idea altogether ?
-
- 2. Pointer type manipulation
- -----------------------------
-
- A very disappointing thing in C++ (unless I am mistaken and it is actually
- possible to do so) is the following situation:
-
- If A is a class, then most operations on A can be redefined.
- Because A is a full blown type.
-
- Sadly, the same can not be said about A* (type: pointer to A).
-
- Even though A* is a type, none of its default manipulations
- can be redefined.
-
- Example: You can tell C++, that you want to gain control of the
- situation whenever an object of type A is duplicated.
-
- You do so by redefining the default copy constructor and the default
- assignment operator.
-
- But can you tell C++ that you want to gain control whenever a pointer of
- A* is duplicated ? Why can't I redefine the copy constructor for the type A* ?
-
- In my way of looking at thing, that'd be a *great* way of doing clean reference
- counting, instead of half-baked method using a redefinition of operator->.
-
- Comments ?
-
- - Mgix
- ________________________________________________________________________________
- Emmanuel Mogenet <mgix@aw.sgi.com> PGP Key on Request
- Home Page: http://reality.sgi.com/mgix
-
- "Any man who cannot explain his work to a fourteen year old is a charlatan."
-
- -- Jons Jacob Berzelius
-
- ________________________________________________________________________________
-